package com.study.web.controller.goal;

import java.util.List;
import java.util.Arrays;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.study.common.annotation.Log;
import com.study.common.annotation.RepeatSubmit;
import com.study.common.core.controller.AppBaseController;
import com.study.common.core.controller.BaseController;
import com.study.common.core.domain.PageQuery;
import com.study.common.core.domain.R;
import com.study.common.core.page.TableDataInfo;
import com.study.common.core.validate.AddGroup;
import com.study.common.core.validate.EditGroup;
import com.study.common.enums.BusinessType;
import com.study.common.utils.poi.ExcelUtil;
import com.study.goal.domain.bo.IntegralExchangeItemBo;
import com.study.goal.domain.vo.IntegralExchangeItemVo;
import com.study.goal.service.IIntegralExchangeItemService;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;

/**
 * 积分兑换
 *
 * @author MT
 * @date 2025-09-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/exchangeItem")
public class IntegralExchangeItemController extends AppBaseController {

    private final IIntegralExchangeItemService iIntegralExchangeItemService;

    /**
     * 查询积分兑换列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<IntegralExchangeItemVo> list(IntegralExchangeItemBo bo, PageQuery pageQuery) {
        return iIntegralExchangeItemService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出积分兑换列表
     */
    @SaCheckLogin
    @PostMapping("/export")
    public void export(IntegralExchangeItemBo bo, HttpServletResponse response) {
        List<IntegralExchangeItemVo> list = iIntegralExchangeItemService.queryList(bo);
        ExcelUtil.exportExcel(list, "积分兑换", IntegralExchangeItemVo.class, response);
    }

    /**
     * 获取积分兑换详细信息
     *
     * @param id 主键
     */
    @SaCheckLogin
    @GetMapping("/{id}")
    public R<IntegralExchangeItemVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iIntegralExchangeItemService.queryById(id));
    }

    /**
     * 新增积分兑换
     */
    @SaCheckLogin
    @RepeatSubmit()
    @PostMapping("/add")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody IntegralExchangeItemBo bo) {
        return toAjax(iIntegralExchangeItemService.insertByBo(bo));
    }

    /**
     * 修改积分兑换
     */
    @SaCheckLogin
    @PostMapping("/update")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody IntegralExchangeItemBo bo) {
        return toAjax(iIntegralExchangeItemService.updateByBo(bo));
    }

    /**
     * 删除积分兑换
     *
     * @param ids 主键串
     */
    @SaCheckLogin
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iIntegralExchangeItemService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
